package com.candy.sys.service.impl;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.candy.sys.entity.User;
import com.candy.sys.service.IUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户 服务实现类
 * </p>
 *
 * @author pxs
 * @since 2021-06-26
 */
@Service
public class UserServiceImpl extends ServiceImpl<BaseMapper<User>, User> implements IUserService {
	@Override
	public boolean isUniqueLoginName(User user)
	{
		LambdaQueryChainWrapper<User> userLambdaQueryChainWrapper = this.lambdaQuery();
		userLambdaQueryChainWrapper.eq(User::getLoginName,user.getLoginName());
		if(user.getId()!=null)
		{
			userLambdaQueryChainWrapper.ne(User::getId,user.getId());
		}
		return this.getBaseMapper().selectCount(userLambdaQueryChainWrapper.getWrapper())==0;
	}

}
